package com.javacoo.xservice.base.mq;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;

/**
 * <p>说明:</p>
 * <li></li>
 *
 * @author duanyong@jccfc.com
 * @date 2021/6/3 22:58
 */
@Slf4j
public class ChannelConsumer {
    private SimpleMessageListenerContainer container;
    private ChannelParams channelParams;

    public ChannelConsumer(DynamicConsumerContainerFactory fac, ChannelParams channelParams) throws Exception {
        SimpleMessageListenerContainer container = fac.getObject();
        container.setMessageListener(new AbstractIChannelConsumer() {
            @Override
            public boolean process(Message message, Channel channel) {
                log.info("ChannelReceiver,{},{}, {},name,fac.getQueue(),new String(message.getBody())");
                distributionConsumerMsg(message, channel);
                return true;
            }
        });
        this.container = container;
        this.channelParams = channelParams;
    }

    //启动消费者监听
    public void start() {
        container.start();
    }

    //消费者停止监听
    public void stop() {
        container.stop();
    }

    //消费者重启
    public void shutdown() {
        container.shutdown();
    }


    /**
     * 用户扩展处理消息
     */
    public void distributionConsumerMsg(Message message, Channel channel) {

    }
}
